/**
 * 类别action
 */
package com.sjzs.web.action;

import java.io.IOException;
import java.util.Iterator;
import java.util.List;

import net.sf.json.JSONObject;

import com.sjzs.web.common.BaseAction;
import com.sjzs.web.dao.CategoryDao;
import com.sjzs.web.po.Category;
import com.sjzs.web.util.ResponseUtil;

/**
 * 类别Action
 * 
 * @author acer
 * @date 2013-7-25 下午05:40:58
 */
public class CategoryAction extends BaseAction {
	private CategoryDao categoryDao;
	private List categoryList;
	public String loadCategoryByPid(){
		String parentId=getRequest().getParameter("parentId");
		if(parentId==null){
			parentId="0";
		}
		categoryList=categoryDao.searchCategoryByParentId(parentId);
		for (Iterator iterator = categoryList.iterator(); iterator.hasNext();) {
			Category type = (Category) iterator.next();
			System.out.println(type.getCategoryname());
		}
    	JSONObject json = new JSONObject();
    	//json.put("alist", categoryList);
    	json.accumulate("categoryList",categoryList);
//    	getResponse().setContentType("text/json; charset=utf-8");
//    	getResponse().setCharacterEncoding("utf-8");
    	try {
			getResponse().getWriter().print(json);
		} catch (IOException e) {
			e.printStackTrace();
		}
		//ResponseUtil.returnJson(json.toString());
		return null;
	}
	public CategoryDao getCategoryDao() {
		return categoryDao;
	}

	public void setCategoryDao(CategoryDao categoryDao) {
		this.categoryDao = categoryDao;
	}
	public List getCategoryList() {
		return categoryList;
	}
	public void setCategoryList(List categoryList) {
		this.categoryList = categoryList;
	}

}
